#include "mainwindow.h"
#include <QProcess>

MainWindow::MainWindow(QWidget *parent)
    : QMainWindow(parent)
{
    statument = false;
    pushButton = new QPushButton(QIcon(":wifi.png"),"", this);
    QString buttonStyle = "QPushButton{border:none;background-color:rgba(255, 255, 255,100);}";
    pushButton->setStyleSheet(buttonStyle);
    //pushButton->setIcon(QIcon(":wifi.png"));
    pushButton->setIconSize(QSize(80, 80));
    pushButton->setMinimumSize(80, 80);
    pushButton->setMaximumSize(80, 80);

    connect(pushButton,&QPushButton::clicked,this,&MainWindow::on_button_clicked);

    ssidLabel = new QLabel("SSID");
    ssid = new QLineEdit(this);
    passwordLabel = new QLabel("PassWord");
    password = new QLineEdit(this);
    sourceLabel = new QLabel("SourceNET");
    sourceSelect = new QComboBox(this);
    sourceSelect->addItem("enp4s0f0");
    sourceSelect->addItem("wlp3s0");
    sharedLabel = new QLabel("SharedNET");
    sharedSelect = new QComboBox(this);
    sharedSelect->addItem("enp4s0f0");
    sharedSelect->addItem("wlp3s0");

    saveButton = new QPushButton("Save",this);
    saveButton->setMaximumWidth(60);

    QGroupBox *settingGroup = new QGroupBox(tr("Setting"));
    QGridLayout *layout = new QGridLayout;
    layout->addWidget(ssidLabel, 0, 0);
    layout->addWidget(ssid, 0, 1);
    layout->addWidget(passwordLabel, 1, 0);
    layout->addWidget(password, 1, 1);
    layout->addWidget(sourceLabel, 2, 0);
    layout->addWidget(sourceSelect, 2, 1);
    layout->addWidget(sharedLabel, 3, 0);
    layout->addWidget(sharedSelect, 3, 1);
    layout->addWidget(saveButton, 4, 1, Qt::AlignRight);
    layout->setSpacing(15);



    settingGroup->setLayout(layout);

    QVBoxLayout *mainLayout = new QVBoxLayout;
    mainLayout->addWidget(pushButton,1,Qt::AlignCenter);
    mainLayout->addWidget(settingGroup);
    mainLayout->setMargin(20);
    //mainLayout->setAlignment(Qt::AlignCenter);
    //setLayout(mainLayout);

    QWidget* widget = new QWidget(this);
    widget-> setLayout(mainLayout);
    setCentralWidget(widget);
}

MainWindow::~MainWindow()
{

}

void MainWindow::on_button_clicked()
{
    QProcess *proc = new QProcess;
    if(!statument){
        //proc->start("systemctl start create_ap");
        statument = true;
        //pushButton->setText("Stop");
    }else{
        //proc->start("systemctl stop create_ap");
        statument = false;
        //pushButton->setText("Start");
    }

}
